from util.selenium.webdriver.common.by import By

from base.BaseMethod import BM



class ToLeftThree():


    top_frame_loc = (By.CSS_SELECTOR, 'iframe')

    left_frame_loc = (By.CSS_SELECTOR, 'frame#leftFrame')

    accept_loc = (By.CSS_SELECTOR, ".btnBox .btn.ok")

    # left_three_btn_loc = (By.CSS_SELECTOR, 'ul#transmitId li:nth-child(3) a')
    left_three_btn_loc = (By.XPATH, "//ul[@id='transmitId']//a[contains(text(),'高企认定申报')]")

    def __init__(self, driver):
        self.driver = driver

    def to_left_three(self):

        BM.close_current_page(driver=self.driver)
        page_list = self.driver.window_handles
        if len(page_list) > 1:
            self.driver.switch_to.window(page_list[-1])

        if BM.isElementExist(element=self.accept_loc, driver=self.driver):
            BM.click(driver=self.driver, ele_loc=self.accept_loc)

        # # # # # 此时刷新页面，使页面能更快的加载出来。
        # self.driver.refresh()

        # print(self.__class__.__name__)
        BM.wait(driver=self.driver, ele_loc=self.top_frame_loc, time=20)

        BM.cut_over_frame(self.driver, self.top_frame_loc)

        self.driver.switch_to.parent_frame()
        # BM.cut_over_frame(self.driver, self.left_frame_loc)

        BM.click(driver=self.driver, ele_loc=self.left_three_btn_loc)
